package com.song.EMS.service.impl;

import com.song.EMS.bean.Administrator;
import com.song.EMS.dao.impl.AdministratorDaoImpl;
import com.song.EMS.service.AdministratorService;

import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

public class AdministratorServiceImpl implements AdministratorService {
    private AdministratorDaoImpl administratorDao = new AdministratorDaoImpl();

    /**
     * 用户登录
     *
     * @param administratorName 用户名
     * @param password 用户密码
     * @return true 登录成功
     */
    @Override
    public Administrator login(String administratorName, String password) {
        return administratorDao.login(administratorName, password);
    }

    /**
     * 更新登录时间与登录IP地址
     *
     * @param administratorName  用户名
     * @param ipAddress 登录IP地址
     * @param loginTime 登录时间
     */
    @Override
    public void updateLoginTime(String administratorName, String ipAddress, Timestamp loginTime) {
        administratorDao.updateLoginTime(administratorName, ipAddress, loginTime);
    }

    /**
     * 用户的注册
     *
     * @param administrator 用户注册信息
     * @return true 注册成功
     */
    @Override
    public Integer register(Administrator administrator) {
        //用户名是否重复
        if (selectByPhone(null, administrator.getAdministratorName()) != null) {
            return 0;
        }
        //用户手机号是否重复
        if (selectByPhone(administrator.getAdministratorPhone(), null) != null) {
            return -1;
        }
        return administratorDao.register(administrator);
    }
    /**
     * 通过手机号查询用户
     *
     * @param administratorPhone 用户的手机号
     * @return 查询的用户对象
     */
    @Override
    public Administrator selectByPhone(String administratorPhone, String administratorName) {
        return administratorDao.selectByPhone(administratorPhone, administratorName);
    }
}
